package server;

import java.io.*;
import java.net.*;

public class Host implements Runnable {
	
	boolean flag;
	
	public Host() {
		flag = true;
	}
	
	public void stop() throws IOException {
		flag = false;
		ServerService.SERVER_SOCK.close();
		ServerService.SERVER_SOCK = null;
	}
	
	public void run() {
		while(flag) {
			Socket sock = null;
			Connection conn = null;
			try {
				sock = ServerService.SERVER_SOCK.accept();
				conn = new Connection(sock);
				ServerService.CONNECTION_LIST.addConnection(conn);
				Thread t = new Thread(conn);
				conn.setThisThread(t);
				t.start();
			} catch (IOException e) {
//				e.printStackTrace();
			}
		}
	}

}
